package olympicgameslogic;

import java.io.Serializable;

public class Edition implements Serializable,Comparable<Edition> {

   private int year;
   private String city;
   private String officialDesignation;
   private String logo;
   private LinkedList<Delegation> editionDelegationList = new LinkedList();
   private LinkedList<EditionDisciplineEvent> editionDisciplineEventList = new LinkedList();
   private LinkedList<Medal> delegationMedals = new LinkedList();

   EditionDisciplineEvent getEditionDisciplineEvent(DisciplineEvent discEv) {

      for (EditionDisciplineEvent edDiscEv : editionDisciplineEventList) {
	 if (edDiscEv.getEditionDisciplineEvent() == discEv) {
	    return edDiscEv;
	 }
      }
      return null;
   }

   @Override
   public int compareTo(Edition e) {
      return year - e.getYear();
   }

   public static enum GAMESEDITION {

      ANY, SUMMER, WINTER
   };

   public Edition(int year, String city, String officialDesignation, String logo) {
      setYear(year);
      setCity(city);
      setOfficialDesignation(officialDesignation);
      setLogo(logo);
   }

   public Edition(int year) {
      setYear(year);
   }

   public Edition() {
   }

   /**
    * @return the year
    */
   public int getYear() {
      return year;
   }

   /**
    * @return the city
    */
   public String getCity() {
      return city;
   }

   /**
    * @return the officialDesignation
    */
   public String getOfficialDesignation() {
      return officialDesignation;
   }

   /**
    * @return the logo
    */
   public String getLogo() {
      return logo;
   }

   /**
    * @return the delegationList
    */
   public LinkedList<Delegation> getEditionDelegationList() {
      return editionDelegationList;
   }

   /**
    * @return the disciplineEventList
    */
   public LinkedList<EditionDisciplineEvent> getEditionDisciplineEventList() {
      return editionDisciplineEventList;
   }

   /**
    * @param year the year to set
    */
   public void setYear(int year) {
      this.year = year;
   }

   /**
    * @param city the city to set
    */
   public void setCity(String city) {
      this.city = city;
   }

   /**
    * @param officialDesignation the officialDesignation to set
    */
   public void setOfficialDesignation(String officialDesignation) {
      this.officialDesignation = officialDesignation;
   }

   /**
    * @param logo the logo to set
    */
   public void setLogo(String logo) {
      this.logo = logo;
   }

   /**
    * @param delegationList the delegationList to set
    */
   public void setDelegationList(LinkedList<Delegation> editionDelegationList) {
      this.editionDelegationList = editionDelegationList;
   }

   /**
    * @param disciplineEventList the disciplineEventList to set
    */
   public void setEditionDisciplineEventList(LinkedList<EditionDisciplineEvent> editionDisciplineEventList) {
      this.editionDisciplineEventList = editionDisciplineEventList;
   }

   public void addDelegation(Delegation d) {
      editionDelegationList.add(d);
   }

   public Delegation getDelegation(int delegationIndex) {
      return (Delegation) editionDelegationList.getElement(delegationIndex);
   }

   public void addEditionDisciplineEvent(EditionDisciplineEvent editionDisciplineEvent) {
      editionDisciplineEventList.add(editionDisciplineEvent);

   }

   public Delegation getDelegation(String country) {
      for (Delegation d : editionDelegationList) {
	 if (d.getCountry().getCode().trim().equalsIgnoreCase(country)) {
	    return d;
	 }
      }
      return null;
   }

   public LinkedList<Modality> getAvailableModalities() {
      LinkedList<Modality> editionModalities = new LinkedList();
      for (EditionDisciplineEvent editionDisciplineEvent : editionDisciplineEventList) {
	 editionModalities.add(editionDisciplineEvent.getEditionDisciplineEvent().getEventDiscipline().getModality());

      }

      return editionModalities;
   }

   public boolean isEditionModalityAvailable(String modality) {
      for (EditionDisciplineEvent editionDisciplineEvent : editionDisciplineEventList) {
	 if (editionDisciplineEvent.getEditionDisciplineEvent().getEventDiscipline().getModality().getName().equalsIgnoreCase(modality)) {
	    return true;
	 }

      }
      return false;

   }

   public boolean isEditionDisciplibeAvailable(String discipline) {
      for (EditionDisciplineEvent editionDisciplineEvent : editionDisciplineEventList) {
	 if (editionDisciplineEvent.getEditionDisciplineEvent().getEventDiscipline().getName().equalsIgnoreCase(discipline)) {
	    return true;
	 }

      }
      return false;
   }

   @Override
   public String toString() {
      return "" + year;
   }

   public boolean existsNation(Nation n) {
      for (Delegation delegation : editionDelegationList) {
	 if (delegation.getCountry().equals(n)) {
	    return true;
	 }

      }
      return false;
   }
}
